package sample.stormax.pres.news;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.GridView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import sample.stormax.pres.news.adapters.TypeAdapter;
import sample.stormax.pres.news.utils.sharepres.ISharePreferenceOperation;
import sample.stormax.pres.news.utils.sharepres.SPUtils;

/**
 * 导航Activity，GridView选择新闻类型
 */
public class GuideActivity extends AppCompatActivity {

    private static final String TAG = "GuideActivity";

    int[] icons = {
            R.mipmap.shehui_pic,
            R.mipmap.guonei_pic,
            R.mipmap.guoji_pic,
            R.mipmap.yule_pic,
            R.mipmap.tiyu_pic,
            R.mipmap.junshi_pic,
            R.mipmap.keji_pic,
            R.mipmap.caijing_pic,
            R.mipmap.shishang_pic
    };

    @BindView(R.id.guide_grid)
    GridView gridView;

    private TypeAdapter typeAdapter;

    private ISharePreferenceOperation sharePreferenceOp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        ButterKnife.bind(this);
        sharePreferenceOp = new SPUtils(this);

        String[] types = getResources().getStringArray(R.array.types);

        typeAdapter = new TypeAdapter(this, icons, types);
        gridView.setAdapter(typeAdapter);
    }

    @OnClick(R.id.commit_btn)
    void commitTypes() {
        sharePreferenceOp.firstLoad();
        //获取到选中的types，中文
        ArrayList<String> selectedTypes = typeAdapter.getSelectedTypes();

        Intent intent = new Intent(GuideActivity.this, MainActivity.class);
        Bundle bundle = new Bundle();
        bundle.putStringArrayList("TYPE", selectedTypes);
        intent.putExtras(bundle);
        startActivity(intent);
        finish();
    }

}
